﻿using Sidvall.UI.Dialogs;
using Sidvall.UI.ViewModels;
using System.Threading.Tasks;

namespace Sidvall.UI.Wpf.Dialogs
{
    public partial class SecurityDialog
    {
        #region Public Members

        #region ShowAsync

        public async Task ShowAsync(LogOnDialogContext logOnContext, LogOffDialogContext logOffContext, SecurityControlViewModelSettings viewModelSettings, object owner)
        {
            if ((logOnContext == null) && (logOffContext == null))
                return;
            WindowManager.SetWindowOwner(this, owner);
            await this.SecurityControl.InitializeContextAsync(logOnContext, logOffContext, viewModelSettings);
            ShowDialog();
        }

        #endregion

        #endregion
        #region Events

        #region SecurityControl_CloseSelected

        private void SecurityControl_CloseSelected(object sender, System.EventArgs e)
        {
            Close();
        }

        #endregion
        #region SecurityControl_ViewTypeChanged

        private void SecurityControl_ViewTypeChanged(object sender, System.EventArgs e)
        {
            this.Title = this.SecurityControl.ViewModel.ViewTitle;
        }

        #endregion
        #region Window_Activated

        private async void Window_Activated(object sender, System.EventArgs e)
        {
            await this.SecurityControl.StartAsync();
        }

        #endregion

        #endregion
        #region Constructors

        public SecurityDialog()
        {
            InitializeComponent();

            Sidvall.UI.Wpf.ControlManager.SetLanguage(this);
        }

        #endregion
    }
}
